package com.cskaoyan.service.wx.lxc;

import com.cskaoyan.bean.po.MarketCategory;
import com.cskaoyan.bean.po.MarketCategoryExample;
import com.cskaoyan.bean.vo.wxlxc.WxCatalogCurrentVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxCatalogServicelmpl implements WxCatalogService {

    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public WxCatalogCurrentVo queryCatalogCurrent(Integer id) {
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(id);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        return new WxCatalogCurrentVo(null, marketCategory, marketCategories);
    }

    @Override
    public WxCatalogCurrentVo queryCatalogIndex() {
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(0);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        MarketCategory marketCategory = marketCategoryMapper.selectByPrimaryKey(marketCategories.get(0).getId());
        MarketCategoryExample marketCategoryExample2 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria2 = marketCategoryExample.createCriteria();
        criteria2.andPidEqualTo(marketCategories.get(0).getId());
        List<MarketCategory> marketCategories2 = marketCategoryMapper.selectByExample(marketCategoryExample2);
        return new WxCatalogCurrentVo(marketCategories, marketCategory, marketCategories2);
    }
}
